<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>属性操作</title>
    <script type="text/javascript">
    function GetShuX(){
        var _Text = document.getElementById("myDiv").attributes["abc"].nodeName;
        alert(_Text);
        var _Value = document.getElementById("myDiv").attributes["abc"].nodeValue;
        alert(_Value);
    }
    
    function AddShuX(){
        document.getElementById("myDiv").setAttribute("style", "color:#f00;");
        document.getElementById("myDiv").setAttribute("abc", "qwe");
        
        document.getElementById("aa").setAttribute("target", "_blank");
    }

    
    function DelShuX(){
        document.getElementById("myDiv").removeAttribute("style");
        document.getElementById("myDiv").removeAttribute("title");
    }
    </script> 
</head>
<body>
    <div id="myDiv" class="TextColor" abc="123456" title="文本盒子">这是一个div的内容</div>
    <a id="aa" href="JieD.html">超链接</a>
    <input type="button" value="获取属性" onclick="GetShuX()" />
    <input type="button" value="设置属性" onclick="AddShuX()" />
    <input type="button" value="移除属性" onclick="DelShuX()" />
</body>
</html>